package com.getword.web.controller;


import com.getword.domain.ArticleCollect;
import com.getword.service.CollectService;
import com.getword.web.model.ArticleCondition;
import com.getword.web.model.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.*;

/**
 * 视频和文章
 */
@RestController
@RequestMapping("/api/collect")
public class ApiCollectController {
    @Autowired
    private CollectService collectService;

//    @Autowired
//    private MongoTemplate mongoTemplate;

//    @PostMapping
//    public Result create(ArticleCollect collect){
//        return null;
//    }

//    @GetMapping("{id:\\d+}")
//    public Result getInfo(@PathVariable Long id){
//        return null;
//    }

    // 获取某个用户所收藏的文章信息，分页
    @GetMapping
    public Result query(@PageableDefault(page = 1, size = 10) Pageable page, ArticleCondition condition){
        return null;
    }

    // 获取当前用户收藏的文章，分页
    @GetMapping("/article")
    public Result getArticle(int page, int size, Long gradeId){
//        mongoTemplate.updateMulti(Query.query(Criteria.where("userId").is(2)), Update.update("gradeId", 4L), ArticleCollect.class);
        Pageable pageable = PageRequest.of(page-1, size);
        return collectService.getArticleCollect(pageable, gradeId);
    }
    // 获取当前用户收藏的文章，分页
    @GetMapping("/video")
    public Result getVideo(int page, int size, Long gradeId){
//        mongoTemplate.updateMulti(Query.query(Criteria.where("userId").is(2)), Update.update("gradeId", 4L), ArticleCollect.class);
        Pageable pageable = PageRequest.of(page-1, size);
        return collectService.getArticleCollect(pageable, gradeId);
    }
}
